﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using Microsoft.SharePoint;
using System.Web.UI.WebControls;

namespace VisualWebPart
{
    public partial class VisualWebPartMVPUserControl : UserControl, IVisualWebPartMVPUserControl
    {
        VisualWebPartMVPPresenter _presenter;
        VisualWebPartMVPPresenter Presenter
        {
            get
            {
                if (_presenter == null)
                {
                    _presenter = new VisualWebPartMVPPresenter(SPContext.Current.Site);
                    _presenter.View = this;
                }
                return _presenter;
            }
        }

        ListBox listBox;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            listBox = new ListBox();
            Controls.Add(listBox);

            Presenter.OnViewInitialized();            
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //Presenter.OnViewLoaded();
        }

        public void Fill(IList<string> names)
        {
            listBox.DataSource = names;
            listBox.DataBind();
        }
    }
}
